package com.smiier.skin;

import java.util.HashMap;
import java.util.Map;

import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import cn.skinapp.R;

import com.smiier.skin.ui.BasicActivity;
import com.smiier.skin.util.GlobalSettings;
import com.smiiler.skin.haoyaoshi.ParamsEncrypt;
import com.umeng.analytics.MobclickAgent;

public class KepuHaoyaoshiActivity extends BasicActivity {

	private WebView goto_haoyaoshi;

	private ProgressBar progress;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.activity_goto_haoyaoshi_view);

		init();

		goto_haoyaoshi = findViewById(R.id.goto_haoyaoshi, WebView.class);

		progress = findViewById(R.id.progress_bar, ProgressBar.class);

		String seekKey = getIntent().getStringExtra("seekKey");

		progress.setVisibility(View.VISIBLE);

		if (seekKey != null) {
			// UserState 用户登录状态默认是 1 使用固化数据
			Map<String, String[]> paramMap = new HashMap<String, String[]>();

			paramMap.put("method", new String[] { "register" });

			paramMap.put("openId", new String[] { GlobalSettings.sUid + "" });

			paramMap.put("fd_uuid", new String[] { "mfyl" });

			paramMap.put("UserState", new String[] { "1" });

			paramMap.put("seekKey", new String[] { seekKey });
			paramMap.put("entrance", new String[] { "goodsSeekDetails" });

			/*
			 * System.out.println(ParamsEncrypt.generateSign(secretKey,
			 * orderInterface, paramMap));
			 */

			/**
			 * http://m.test.ehaoyao.com/webrGoodsList.do?method=register&openId
			 * =123123&UserState=1&fd_uuid=mfyl&
			 * seekKey=五&entrance=goodsSeekDetails
			 * &sign=5766243a3528b4200f41ada8a7496cff45762c13
			 */

			String sign = ParamsEncrypt.generateSign(GlobalSettings.secretKey,
					GlobalSettings.orderInterface, paramMap);

			String url = GlobalSettings.SERVER_URL_HAOYAOSHI + "&openId="
					+ GlobalSettings.sUid + "&UserState=1"
					+ "&fd_uuid=mfyl&seekKey=" + seekKey + "&entrance="
					+ GlobalSettings.orderInterface + "&sign=" + sign;
			WebSettings webSettings = goto_haoyaoshi.getSettings();
			/*webSettings.setJavaScriptEnabled(true);
			webSettings.setUseWideViewPort(true);
			webSettings.setLoadWithOverviewMode(true);
			
			
			//启用触控缩放
			webSettings.setBuiltInZoomControls(true);
	        //启用支持视窗meta标记（可实现双击缩放）
			webSettings.setUseWideViewPort(true);
	        //以缩略图模式加载页面
			webSettings.setLoadWithOverviewMode(true);*/
			
			webSettings.setJavaScriptEnabled(true);
			webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
			webSettings.setAllowFileAccess(true);// 设置允许访问文件数据
			webSettings.setSupportZoom(true);
			webSettings.setBuiltInZoomControls(true);
			webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
			webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
			webSettings.setDomStorageEnabled(true);
			webSettings.setDatabaseEnabled(true);
			
			goto_haoyaoshi.setWebChromeClient(new WebChromeClient());
			
			// webview.loadUrl("http://123.57.2.103/Symptom/cuochuang.html");

			// goto_haoyaoshi.loadUrl(url);

			goto_haoyaoshi.loadUrl(url);

			goto_haoyaoshi.setWebViewClient(new WebViewClient() {
				@Override
				public boolean shouldOverrideUrlLoading(WebView view, String url) {
					// TODO Auto-generated method stub
					progress.setVisibility(View.GONE);
					view.loadUrl(url);
					return true;
				}
			});

		} else {
			return;
		}

	}

	@Override
	public boolean onKeyDown(int keyCoder, KeyEvent event) {

		if (goto_haoyaoshi.canGoBack() && keyCoder == KeyEvent.KEYCODE_BACK) {

			goto_haoyaoshi.goBack(); // goBack()表示返回webView的上一页面

			return true;

		} else {

			onBackPressed();
		}

		return false;

	}
	
	
/*	@Override
	public void onResume() {
		super.onResume();
		MobclickAgent.onResume(getContext());
	}

	@Override
	public void onPause() {
		super.onPause();
		MobclickAgent.onPause(getContext());
	}*/

}
